<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('简历管理')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <p>职位类别：</p>
                                <select name="positionType" th:with="type=${@dict.getType('job_position_type')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <p>地区：</p>
                                <select name="area" th:with="type=${@dict.getType('job_area')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <p>薪资：</p>
                                <select name="salary" th:with="type=${@dict.getType('job_salary')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <p>简历状态：</p>
                                <select name="status" th:with="type=${@dict.getType('job_resume_status')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" >
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" >
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" >
                    <i class="fa fa-remove"></i> 删除
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var positionTypeDatas = [[${@dict.getType('job_position_type')}]];
        var areaDatas = [[${@dict.getType('job_area')}]];
        var salaryDatas = [[${@dict.getType('job_salary')}]];
        var statusDatas = [[${@dict.getType('job_resume_status')}]];
        var prefix = ctx + "job/resume";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                importUrl: prefix + "/importData",
                modalName: "简历",
                columns: [{
                    checkbox: true
                },
                {
                    field : 'resumeId', 
                    title : '简历id',
                    visible: false
                },
                    {
                        field : 'resumeName',
                        title : '简历名称'
                    },

                    {
                        field : 'name',
                        title : '求职者姓名'
                    },
                {
                    field : 'positionType', 
                    title : '职位类别',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(positionTypeDatas, value);
                    }
                },
                {
                    field : 'area', 
                    title : '地区',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(areaDatas, value);
                    }
                },
                {
                    field : 'salary', 
                    title : '薪资范围',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(salaryDatas, value);
                    }
                },
                {
                    field : 'status', 
                    title : '简历状态',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(statusDatas, value);
                    }
                },
                    {
                        field : 'uploadStatus',
                        title : '附件状态'
                    },
                    {
                        field : 'fileName',
                        title : '附件名称'
                    },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="importExcel(\'' + row.resumeId + '\')"><i class="fa fa-upload"></i>上传简历附件</a> ');
                        if (row.uploadStatus == '已上传附件') {
                            actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="downloadExcel(\'' + row.resumeId + '\', \'' + row.name + '\')"><i class="fa fa-download"></i>下载简历附件</a> ');
                        }
                        if (row.status == 0) {
                            actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="enable(\'' + row.resumeId + '\')"><i class="fa fa-edit"></i>发布</a> ');
                        } else {
                            actions.push('<a class="btn btn-info btn-xs " href="javascript:void(0)" onclick="inviteDetail(\'' + row.resumeId + '\')"><i class="fa fa-list-ul"></i>邀请情况</a> ');
                        }
                        actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="$.operate.edit(\'' + row.resumeId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.resumeId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        /* 简历发布 */
        function enable(resumeId) {
            $.modal.confirm("确认要发布该简历吗？", function() {
                $.operate.post(prefix + "/enable", { "resumeId": resumeId, "status": 1 });
            })
        }
        /* 邀请情况 */
        function inviteDetail(resumeId) {
            var url = prefix + "/inviteDetail/"+ resumeId;
            $.modal.openTab("邀请情况", url);
        }

        function downloadExcel(resumeId, name) {
            var url = prefix + "/downloadFile";
            window.location.href = url + '?resumeId=' + resumeId + '&name=' + name;

        }
        function importExcel(resumeId) {

            layer.open({
                type: 1,
                area: ['400px', '230px'],
                fix: false,
                //不固定
                maxmin: true,
                shade: 0.5,
                title: '上传' + table.options.modalName + '附件',
                content: $('#importTpl').html(),
                btn: ['<i class="fa fa-check"></i> 上传', '<i class="fa fa-remove"></i> 取消'],
                // 弹层外区域关闭
                shadeClose: true,
                btn1: function(index, layero){

                    var index = layer.load(2, {shade: false});
                    $.modal.disable();
                    var formData = new FormData();
                    formData.append("file", layero.find('#file')[0].files[0]);
                    $.ajax({
                        url: table.options.importUrl + '?resumeId=' + resumeId,
                        data: formData,
                        cache: false,
                        contentType: false,
                        processData: false,
                        type: 'POST',
                        success: function (result) {
                            if (result.code == web_status.SUCCESS) {
                                $.modal.closeAll();
                                $.modal.alertSuccess(result.msg);
                                $.table.refresh();
                            } else if (result.code == web_status.WARNING) {
                                layer.close(index);
                                $.modal.enable();
                                $.modal.alertWarning(result.msg)
                            } else {
                                layer.close(index);
                                $.modal.enable();
                                $.modal.alertError(result.msg);
                            }
                        }
                    });
                }
            });
        }
    </script>
     <!-- 导入区域 -->
     <script id="importTpl" type="text/template">
         <form enctype="multipart/form-data" class="mt20 mb10">
             <div class="col-xs-offset-1" >
                 <input type="file" id="file" name="file"/>
             </div>
         </form>
     </script>
</body>
</html>